﻿// ===============================================================================
// MarkupControl.cs
// EOS Web Fraework
// ===============================================================================
// Copyright (c) EOS Development Group. All rights reserved.
// ===============================================================================

namespace EOS.Framework.Web.Mvc
{
    using System;
    using EOS.Framework.Tools.Aspects;

    /// <summary>
    /// Base class for all controls with an internal markup.
    /// </summary>
    public abstract class MarkupControl : Control
    {
        /// <summary>
        /// The internal markup file.
        /// </summary>
        protected IMarkup _markup;

        /// <summary>
        /// Gets the current markup of the control.
        /// </summary>
        /// <value>The current markup.</value>
        public virtual IMarkup Markup
        {
            get { return _markup; }
        }

        /// <summary>
        /// Sets the markup for this control.
        /// </summary>
        /// <param name="markup">The markup. Cannot be null
        /// (Nothing in Visual Basic).</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="markup"/> is null (Nothing in Visual Basic).</exception>
        [ParamNotNull("markup")]
        public virtual void SetMarkup(IMarkup markup)
        {
            this._markup = markup;
        }

        /// <summary>
        /// Replaces the key with the specified value.
        /// </summary>
        /// <param name="key">The key to replace. Cannot be null or
        /// empty or contains only blanks.</param>
        /// <param name="value">The value string. Cannot be null (Nothing in Visual Basic).</param>
        /// <exception cref="ArgumentNullException">
        /// 	<para><paramref name="key"/> is null (Nothing in Visual Basic).</para>
        /// 	<para>- or -</para>
        /// 	<para><paramref name="value"/> is null (Nothing in Visual Basic).</para>
        /// </exception>
        /// <exception cref="ArgumentException"><paramref name="key"/> is empty or 
        /// contains only blanks.</exception>
        /// <remarks>If the markup contains a value with the following pattern #{[KEY]} it can
        /// be replaced with this method.</remarks>
        [ParamNotNullOrEmpty("key"), ParamNotNull("value")]
        public void SetValue(string key, string value)
        {
            Markup.SetValue(key, value);
        }

        /// <summary>
        /// Replaces the key with the specified value, which is formatted with the specified arguments.
        /// </summary>
        /// <param name="key">The key to replace. Cannot be null or
        /// empty or contains only blanks.</param>
        /// <param name="value">The value string. Cannot be null (Nothing in Visual Basic).</param>
        /// <param name="args">The arguments for string formatting.</param>
        /// <exception cref="ArgumentNullException">
        /// 	<para><paramref name="key"/> is null (Nothing in Visual Basic).</para>
        /// 	<para>- or -</para>
        /// 	<para><paramref name="value"/> is null (Nothing in Visual Basic).</para>
        /// </exception>
        /// <exception cref="ArgumentException"><paramref name="key"/> is empty or
        /// contains only blanks.</exception>
        /// <remarks>If the markup contains a value with the following pattern #{[KEY]} it can
        /// be replaced with this method.</remarks>
        [ParamNotNullOrEmpty("key"), ParamNotNull("value")]
        public void SetValue(string key, string value, params object[] args)
        {
            Markup.SetValue(key, value, args);
        }

        /// <summary>
        /// Attaches an control to the markup.
        /// </summary>
        /// <param name="key">The key of the tag, where to attach the control to. Cannot be null or
        /// empty or contains only blanks.</param>
        /// <param name="control">The control to attach.</param>
        /// <exception cref="ArgumentNullException">
        /// 	<para><paramref name="key"/> is null (Nothing in Visual Basic).</para>
        /// 	<para>- or -</para>
        /// 	<para><paramref name="control"/> is null (Nothing in Visual Basic).</para>
        /// </exception>
        /// <exception cref="ArgumentException"><paramref name="key"/> is a string
        /// of length 0 or contains only blanks.</exception>
        [ParamNotNullOrEmpty("key"), ParamNotNull("control")]
        public void Attach(string key, Control control)
        {
            Markup.Attach(key, control);
        }

        /// <summary>
        /// Attaches an control to the markup.
        /// </summary>
        /// <param name="key">The key of the tag, where to attach the control to. Cannot be null or
        /// empty or contains only blanks.</param>
        /// <param name="control">The control to attach.</param>
        /// <param name="throwExceptions">if set to <c>true</c> the method throws an exception, if the
        /// key cannot been found.</param>
        /// <exception cref="ArgumentNullException">
        /// 	<para><paramref name="key"/> is null (Nothing in Visual Basic).</para>
        /// 	<para>- or -</para>
        /// 	<para><paramref name="control"/> is null (Nothing in Visual Basic).</para>
        /// </exception>
        /// <exception cref="ArgumentException"><paramref name="key"/> is a string
        /// of length 0 or contains only blanks.</exception>
        [ParamNotNullOrEmpty("key"), ParamNotNull("control")]
        public void Attach(string key, Control control, bool throwExceptions)
        {
            Markup.Attach(key, control, throwExceptions);
        }

        /// <summary>
        /// Hides the tag with the specified key.
        /// </summary>
        /// <param name="key">The key of the tag to hide. Cannot be null or
        /// empty or contains only blanks.</param>
        /// <exception cref="ArgumentNullException"><paramref name="key"/> is null 
        /// (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentException"><paramref name="key"/> is a string
        /// of length 0 or contains only blanks.</exception>
        [ParamNotNullOrEmpty("key")]
        public void Hide(string key)
        {
            Markup.Hide(key);
        }

        /// <summary>
        /// Hides the tag with the specified key.
        /// </summary>
        /// <param name="key">The key of the tag to hide. Cannot be null or
        /// empty or contains only blanks.</param>
        /// <param name="throwExceptions">if set to <c>true</c> the method throws an exception, if the
        /// key cannot been found.</param>
        /// <exception cref="ArgumentNullException"><paramref name="key"/> is null
        /// (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentException"><paramref name="key"/> is a string
        /// of length 0 or contains only blanks.</exception>
        [ParamNotNullOrEmpty("key")]
        public void Hide(string key, bool throwExceptions)
        {
            Markup.Hide(key, throwExceptions);
        }
    }
}
